﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.UpdateContinuousMfg.CCUiUCMUpdateContinuousMfgExposedTCDlg
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.CreateContinuousMFGFromCurve;
using EngineeringInternalExtension;
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Forms;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace DnProcessSimulateCommands.UpdateContinuousMfg;

public class CCUiUCMUpdateContinuousMfgExposedTCDlg : TxForm
{
  private CApUCMUpdateContinuousMfgExposedTCLogic _logic;
  private ITxValidator _curveValidator;
  private IContainer components;
  private RadioButton rbSetSourceCurve;
  private TxObjEditBoxCtrl txebSourceCurve;
  private Button btnOK;
  private Button btnCancel;
  private RadioButton rbRestoreGeometryOfItemRevision;
  private RadioButton rbUpdateChangesToRevision;
  private RadioButton rbUpdateLocalMfgAndAddChangesToProcess;
  private RadioButton rbUpdateLocalMfgOnly;
  private TxObjComboBoxCtrl txcbProcess;
  private Panel panSourceCurveOptions;

  public CCUiUCMUpdateContinuousMfgExposedTCDlg()
  {
    this.InitializeComponent();
    this._curveValidator = (ITxValidator) new CApCMCCurvesValidator();
    this._logic = new CApUCMUpdateContinuousMfgExposedTCLogic();
  }

  private void CCUiUCMUpdateContinuousMfgTCDlg_Load(object sender, EventArgs e)
  {
    ((Control) this).Text = string.Format(UCMStringTable.UCM_DialogTitle, (object) ((TxMfgFeature) this._logic.SelectedSeam).Name);
    this.SetSourceCurvePickProviders();
    this.SetSourceCurveValidator();
    this.txebSourceCurve.PickLevel = (TxPickLevel) 2;
    this.txebSourceCurve.ListenToPick = true;
    this.txebSourceCurve.Focus();
    this.SetProcessValidator();
    this.FillProcessList();
    this.EnableOrDisableAcceptButton();
    this.rbRestoreGeometryOfItemRevision.Enabled = this._logic.ShouldEnableRestoreGeometryOfItemRevisionCheckbox();
    this.txcbProcess.Enabled = this.rbUpdateLocalMfgAndAddChangesToProcess.Checked;
    this.rbUpdateChangesToRevision.Enabled = ((TxMfgFeature) this._logic.SelectedSeam).CanBeModified;
    TxSeamMfgFeatureEx seamMfgFeatureEx = new TxSeamMfgFeatureEx(this._logic.SelectedSeam);
    if (seamMfgFeatureEx == null || !seamMfgFeatureEx.IsLocal)
      return;
    this.rbRestoreGeometryOfItemRevision.Enabled = seamMfgFeatureEx.IsLocal;
  }

  private void btnCancel_Click(object sender, EventArgs e) => ((Form) this).Close();

  private void btnOK_Click(object sender, EventArgs e)
  {
    Cursor current = Cursor.Current;
    Cursor.Current = Cursors.WaitCursor;
    bool flag = true;
    if (this.rbSetSourceCurve.Checked)
    {
      if (this._logic.ChangeCurve(this.txebSourceCurve.Object))
      {
        if (this.rbUpdateLocalMfgAndAddChangesToProcess.Checked)
          this._logic.StoreJtOnProcess(this.txcbProcess.Object);
        else if (this.rbUpdateChangesToRevision.Checked)
        {
          if (TxMessageBox.Show(UCMStringTable.ResourceManager.GetString("UCMTC_UpdateRevisionMessage"), UCMStringTable.ResourceManager.GetString("UCMTC_UpdateRevisionTitle"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            this._logic.UpdateChangesToRevision();
          else
            flag = false;
        }
      }
      else
      {
        int num = (int) TxMessageBox.Show(UCMStringTable.ResourceManager.GetString("UMC_ChangeSourceCurveMessage"), UCMStringTable.ResourceManager.GetString("UMC_ErrorTitle"), MessageBoxButtons.OK, MessageBoxIcon.Hand);
      }
    }
    else if (TxMessageBox.Show(UCMStringTable.ResourceManager.GetString("UCMTC_ReloadComponentFromRevisionMessage"), UCMStringTable.ResourceManager.GetString("UCMTC_ReloadComponentTitle"), MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
      this._logic.ReloadComponent();
    else
      flag = false;
    Cursor.Current = current;
    this._logic.SelectTheSeamMfg();
    if (!flag)
      return;
    ((Form) this).Close();
  }

  private void txcbSourceCurve_Picked(object sender, TxObjEditBoxCtrl_PickedEventArgs args)
  {
    this.EnableOrDisableAcceptButton();
  }

  private void txcbSourceCurve_TypeValid(object sender, EventArgs e)
  {
    this.EnableOrDisableAcceptButton();
  }

  private void txcbSourceCurve_TypeInvalid(object sender, EventArgs e)
  {
    this.EnableOrDisableAcceptButton();
  }

  private void rbSetSourceCurve_CheckedChanged(object sender, EventArgs e)
  {
    this.txebSourceCurve.Enabled = this.rbSetSourceCurve.Checked;
    this.rbUpdateLocalMfgOnly.Enabled = this.rbSetSourceCurve.Checked;
    this.rbUpdateLocalMfgAndAddChangesToProcess.Enabled = this.rbSetSourceCurve.Checked;
    this.rbUpdateChangesToRevision.Enabled = this.rbSetSourceCurve.Checked && ((TxMfgFeature) this._logic.SelectedSeam).CanBeModified;
    this.txcbProcess.Enabled = this.rbUpdateLocalMfgAndAddChangesToProcess.Checked && this.rbUpdateLocalMfgAndAddChangesToProcess.Enabled;
    this.EnableOrDisableAcceptButton();
  }

  private void rbUpdateLocalMfgAndAddChangesToProcess_CheckedChanged(object sender, EventArgs e)
  {
    this.txcbProcess.Enabled = this.rbUpdateLocalMfgAndAddChangesToProcess.Checked;
    this.EnableOrDisableAcceptButton();
  }

  private void txcbProcess_Picked(object sender, TxObjComboBoxCtrl_PickedEventArgs args)
  {
    this.EnableOrDisableAcceptButton();
  }

  private void txcbProcess_SelectionChanged(object sender, EventArgs e)
  {
    this.EnableOrDisableAcceptButton();
  }

  private void SetSourceCurvePickProviders()
  {
    // ISSUE: unable to decompile the method.
  }

  private void SetSourceCurveValidator() => this.txebSourceCurve.SetValidator(this._curveValidator);

  private void SetProcessValidator()
  {
    this.txcbProcess.SetValidator(this._logic.GetTCProcessValidator());
  }

  private void FillProcessList()
  {
    foreach (ITxObject tcProcess in (Collection<ITxObject>) this._logic.GetTCProcessList())
      this.txcbProcess.AddItem(tcProcess.Name, tcProcess);
    this.txcbProcess.SelectObject((ITxObject) this._logic.GetRootProcess());
  }

  private void EnableOrDisableAcceptButton()
  {
    this.btnOK.Enabled = this._logic.ShouldEnableOKButton(this.txebSourceCurve.Object, this.txcbProcess.Object, this.rbUpdateLocalMfgAndAddChangesToProcess.Checked, this.rbUpdateChangesToRevision.Checked, this.rbRestoreGeometryOfItemRevision.Checked);
    if (!this.btnOK.Enabled)
      return;
    this.btnOK.Focus();
  }

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  private void InitializeComponent()
  {
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CCUiUCMUpdateContinuousMfgExposedTCDlg));
    this.rbSetSourceCurve = new RadioButton();
    this.txebSourceCurve = new TxObjEditBoxCtrl();
    this.btnOK = new Button();
    this.btnCancel = new Button();
    this.rbRestoreGeometryOfItemRevision = new RadioButton();
    this.rbUpdateChangesToRevision = new RadioButton();
    this.rbUpdateLocalMfgAndAddChangesToProcess = new RadioButton();
    this.rbUpdateLocalMfgOnly = new RadioButton();
    this.txcbProcess = new TxObjComboBoxCtrl();
    this.panSourceCurveOptions = new Panel();
    this.panSourceCurveOptions.SuspendLayout();
    ((Control) this).SuspendLayout();
    componentResourceManager.ApplyResources((object) this.rbSetSourceCurve, "rbSetSourceCurve");
    this.rbSetSourceCurve.Checked = true;
    this.rbSetSourceCurve.Name = "rbSetSourceCurve";
    this.rbSetSourceCurve.TabStop = true;
    this.rbSetSourceCurve.UseVisualStyleBackColor = true;
    this.rbSetSourceCurve.CheckedChanged += new EventHandler(this.rbSetSourceCurve_CheckedChanged);
    this.txebSourceCurve.KeepFaceEmphasizedWhenControlIsNotFocused = true;
    this.txebSourceCurve.ListenToPick = false;
    componentResourceManager.ApplyResources((object) this.txebSourceCurve, "txebSourceCurve");
    ((Control) this.txebSourceCurve).Name = "txebSourceCurve";
    this.txebSourceCurve.Object = (ITxObject) null;
    this.txebSourceCurve.PickAndClear = false;
    this.txebSourceCurve.PickLevel = (TxPickLevel) 1;
    this.txebSourceCurve.PickOnly = false;
    this.txebSourceCurve.ReadOnly = false;
    this.txebSourceCurve.ValidatorType = (TxValidatorType) 1;
    this.txebSourceCurve.TypeInvalid += new EventHandler(this.txcbSourceCurve_TypeInvalid);
    this.txebSourceCurve.TypeValid += new EventHandler(this.txcbSourceCurve_TypeValid);
    this.txebSourceCurve.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.txcbSourceCurve_Picked);
    componentResourceManager.ApplyResources((object) this.btnOK, "btnOK");
    this.btnOK.Name = "btnOK";
    this.btnOK.UseVisualStyleBackColor = true;
    this.btnOK.Click += new EventHandler(this.btnOK_Click);
    componentResourceManager.ApplyResources((object) this.btnCancel, "btnCancel");
    this.btnCancel.Name = "btnCancel";
    this.btnCancel.UseVisualStyleBackColor = true;
    this.btnCancel.Click += new EventHandler(this.btnCancel_Click);
    componentResourceManager.ApplyResources((object) this.rbRestoreGeometryOfItemRevision, "rbRestoreGeometryOfItemRevision");
    this.rbRestoreGeometryOfItemRevision.Name = "rbRestoreGeometryOfItemRevision";
    this.rbRestoreGeometryOfItemRevision.UseVisualStyleBackColor = true;
    componentResourceManager.ApplyResources((object) this.rbUpdateChangesToRevision, "rbUpdateChangesToRevision");
    this.rbUpdateChangesToRevision.Name = "rbUpdateChangesToRevision";
    this.rbUpdateChangesToRevision.UseVisualStyleBackColor = true;
    componentResourceManager.ApplyResources((object) this.rbUpdateLocalMfgAndAddChangesToProcess, "rbUpdateLocalMfgAndAddChangesToProcess");
    this.rbUpdateLocalMfgAndAddChangesToProcess.Name = "rbUpdateLocalMfgAndAddChangesToProcess";
    this.rbUpdateLocalMfgAndAddChangesToProcess.UseVisualStyleBackColor = true;
    this.rbUpdateLocalMfgAndAddChangesToProcess.CheckedChanged += new EventHandler(this.rbUpdateLocalMfgAndAddChangesToProcess_CheckedChanged);
    componentResourceManager.ApplyResources((object) this.rbUpdateLocalMfgOnly, "rbUpdateLocalMfgOnly");
    this.rbUpdateLocalMfgOnly.Checked = true;
    this.rbUpdateLocalMfgOnly.Name = "rbUpdateLocalMfgOnly";
    this.rbUpdateLocalMfgOnly.TabStop = true;
    this.rbUpdateLocalMfgOnly.UseVisualStyleBackColor = true;
    this.txcbProcess.DropDownHeight = 106;
    this.txcbProcess.DropDownStyle = ComboBoxStyle.DropDownList;
    this.txcbProcess.ListenToPick = true;
    componentResourceManager.ApplyResources((object) this.txcbProcess, "txcbProcess");
    ((Control) this.txcbProcess).Name = "txcbProcess";
    this.txcbProcess.Object = (ITxObject) null;
    this.txcbProcess.PickLevel = (TxPickLevel) 1;
    this.txcbProcess.ValidatorType = (TxValidatorType) 1;
    this.txcbProcess.SelectionChanged += new EventHandler(this.txcbProcess_SelectionChanged);
    this.txcbProcess.Picked += new TxObjComboBoxCtrl_PickedEventHandler(this.txcbProcess_Picked);
    this.panSourceCurveOptions.Controls.Add((Control) this.txcbProcess);
    this.panSourceCurveOptions.Controls.Add((Control) this.rbUpdateLocalMfgOnly);
    this.panSourceCurveOptions.Controls.Add((Control) this.rbUpdateLocalMfgAndAddChangesToProcess);
    this.panSourceCurveOptions.Controls.Add((Control) this.rbUpdateChangesToRevision);
    componentResourceManager.ApplyResources((object) this.panSourceCurveOptions, "panSourceCurveOptions");
    this.panSourceCurveOptions.Name = "panSourceCurveOptions";
    componentResourceManager.ApplyResources((object) this, "$this");
    ((ContainerControl) this).AutoScaleMode = AutoScaleMode.Font;
    ((Control) this).Controls.Add((Control) this.rbRestoreGeometryOfItemRevision);
    ((Control) this).Controls.Add((Control) this.btnCancel);
    ((Control) this).Controls.Add((Control) this.btnOK);
    ((Control) this).Controls.Add((Control) this.txebSourceCurve);
    ((Control) this).Controls.Add((Control) this.rbSetSourceCurve);
    ((Control) this).Controls.Add((Control) this.panSourceCurveOptions);
    ((Form) this).FormBorderStyle = FormBorderStyle.FixedDialog;
    ((Form) this).MaximizeBox = false;
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (CCUiUCMUpdateContinuousMfgExposedTCDlg);
    ((Form) this).Load += new EventHandler(this.CCUiUCMUpdateContinuousMfgTCDlg_Load);
    this.panSourceCurveOptions.ResumeLayout(false);
    this.panSourceCurveOptions.PerformLayout();
    ((Control) this).ResumeLayout(false);
    ((Control) this).PerformLayout();
  }
}
